package com.maimao.goods.client.factory;

import com.maimao.core.model.resp.Result;
import com.maimao.goods.client.EsClient;
import com.maimao.goods.client.EsDocClient;
import com.maimao.model.goods.log.GoodsCheck;
import com.maimao.model.goods.log.GoodsCheckInput;
import com.maimao.model.search.DocInput;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class EsFallBackFactory implements FallbackFactory<EsClient> {

    @Override
    public EsClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new EsClient() {
            @Override
            public Result save(GoodsCheck goodsCheck) {
                log.error("调用[EsClient-save({})]出错 :{}", goodsCheck, errorMsg);
                return Result.fail(errorMsg);
            }

            @Override
            public Result list(GoodsCheckInput checkInput) {
                log.error("调用[EsClient-list({})]出错 :{}", checkInput, errorMsg);
                return Result.fail(errorMsg);
            }


            @Override
            public Result updateStatus(GoodsCheck goodsCheck) {
                log.error("调用[EsClient-updateStatus({})]出错 :{}", goodsCheck, errorMsg);
                return Result.fail(errorMsg);
            }


        };
    }
}
